// 导入
require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.less')
require('../font/iconfont.css')
require('../css/home.less')
// 导入工具js
const util = require('../util/util')
// 导入swiper
require('../libs/swiper/swiper-bundle.min.css')

// 引入weui
require('weui')
const weui = require('weui.js')
// 引入axios
const axios = require('axios')

const Swiper = require('../libs/swiper/swiper-bundle.min')

// 引入swiper



document.addEventListener('DOMContentLoaded', function () {
    // 获取元素
    const rank = document.querySelector('#rank')
    const punchDay = document.querySelector('#punchDay')
    const todayPunch = document.querySelector('#todayPunch')
    const badge = document.querySelector('#badge')
    const motionData = document.querySelector('#motionData')
    const train = document.querySelector('#train')

    // 底部导航
    util.fixBottomNav('home')

    function setSwiper() {
        // 初始化swiper插件
        const mySwiper = new Swiper('.swiper', {
            loop: true, // 循环模式选项
            // 如果需要分页器
            pagination: {
                el: '.swiper-pagination',
            },
            autoplay: {
                delay: 1500,
                stopOnLastSlide: false,
                disableOnInteraction: false,
            },
        })
    }
    setSwiper()
    // 首页数据渲染
    axios.get('http://139.9.177.51:8099/headPageInfo', {
        params: {
            userId: localStorage.getItem('userId')
        }
    }).then(function (res) {
        // console.log(res);
        if (res.data.status === 0) {
            rank.textContent = res.data.data.rank
            punchDay.textContent = res.data.data.punchIn
            badge.textContent = res.data.data.insigniaNum
            // rank.textContent = res.data.data.rank
            // console.log(res.data.data.isPunch);
            res.data.data.isPunch == "true" ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
        }
    })
    // 今日打卡
    todayPunch.addEventListener('click', function () {
        axios.get('http://139.9.177.51:8099/clockIn', {
            params: {
                userId: localStorage.getItem('userId')
            }
        }).then(function (res) {
            if (res.data.status === 0) {
                todayPunch.textContent = '已打卡'
                punchDay.textContent++
                weui.toast('打卡成功')
            } else {
                weui.toast('已打卡')
            }
        })
    })
    // 点击跳转到运动数据页面
    motionData.addEventListener('click', function () {
        location.href = './me-data.html'
    })
    // 点击跳转到训练课程页面
    train.addEventListener('click', function () {
        location.href = './motion-curriculum.html'
    })
})